package com.skymxc.skin

import android.app.Application
import android.content.Context
import android.content.SharedPreferences

/**
 * <p>
 * 偏好设置
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/9/20  10:05 下午
 */
class SkinPreferences private constructor(context:Context){
    companion object {
        private const val KEY_PATH = "skin_path"
        private const val NAME = "skin"
        @Volatile
        private var _instance:SkinPreferences?= null
       internal fun init(application: Application){
            _instance = SkinPreferences(application)
        }
        fun getInstance():SkinPreferences{
            return _instance!!
        }
    }

    private val prf:SharedPreferences = context.getSharedPreferences(NAME,Context.MODE_PRIVATE)

    fun setSkin(skin:String){
        prf.edit()
            .putString(KEY_PATH,skin)
            .apply()
    }

    fun getSkin():String? = prf.getString(KEY_PATH,null)

    fun reset(){
        prf.edit().remove(KEY_PATH).apply()
    }

}